﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Entity;
using Microsoft.Xna.Framework;
using Spinning.Spinning.Scenes.ProcessScene.TopMembers;
using Spinning.Spinning.Unitity;
using Spinning.Spinning.ScrollLayout;
using Spinning.Spinning.Interface;

namespace Spinning.Spinning.Scenes.ProcessScene.Store
{
    class StoreSpinningScene : BaseScene, ISaveLoad
    {
        List<ScrollLayoutElementSpinningForStore> totalPriceList = new List<ScrollLayoutElementSpinningForStore>();
        public StoreSpinningScene()
        {
            Size = new Vector2(426, 575);
        }

        public override void OnLoad()
        {
            base.OnLoad();

            ScrollMenu scs = new ScrollMenu();//不用改
            scs.Position = new Vector2(11, 30);
            scs.Color = Color.Transparent;
            scs.Size = new Vector2(405, 286 + 138);
            scs.OnLoad();
            Attach(scs);


            ScrollLayoutElementSpinningForStore ses = new ScrollLayoutElementSpinningForStore();
           // ses.OnLoad();
           // ses.SpiningType = Constants.SpinningType.Omega;
           //// ses.State_Type = ScrollLayoutElementSpinningForStore.StateType.Normal;
           // scs.AddItem(ses);
           // totalPriceList.Add(ses);

            //ses = new ScrollLayoutElementSpinningForStore();
            ses.OnLoad();
            ses.SpiningType = Constants.SpinningType.India;
            //ses.State_Type = ScrollLayoutElementSpinningForStore.StateType.Disable;
            ses.SpinningPrice = 200;
            scs.AddItem(ses);
            totalPriceList.Add(ses);

            ses = new ScrollLayoutElementSpinningForStore();
            ses.OnLoad();
            ses.SpiningType = Constants.SpinningType.Tiawan;
            //ses.State_Type = ScrollLayoutElementSpinningForStore.StateType.Focus;
            ses.SpinningPrice = 200;
            scs.AddItem(ses);
            totalPriceList.Add(ses);

            ses = new ScrollLayoutElementSpinningForStore();
            ses.OnLoad();
            ses.SpiningType = Constants.SpinningType.Russia;
            ses.SpinningPrice = 200;
            scs.AddItem(ses);
            totalPriceList.Add(ses);

            /////////

            SortChildren();
        }

        public int TotalPrice
        {
            get
            {
                int t = 0;
                foreach (ScrollLayoutElementSpinningForStore sp in totalPriceList)
                {
                    if (sp.State_Type == ScrollLayoutElementSpinningForStore.StateType.Focus)
                        t += sp.SpinningPrice;
                }
                return t;
            }
        }

        public override BaseScene Clone()
        {
            throw new NotImplementedException();
        }

        public void Save(Unitity.Storage.SaveData state)
        {
            state.BuyedSpinnings.Clear();
            foreach (ScrollLayoutElementSpinningForStore sp in totalPriceList)
            {
                state.BuyedSpinnings.Add(ScrollLayoutElementSpinningForStore.StateType.Normal);
            }

            for (int i = 0; i < totalPriceList.Count; i++)
            {
                ScrollLayoutElementSpinningForStore sp = totalPriceList[i];
                if (sp.State_Type == ScrollLayoutElementSpinningForStore.StateType.Focus)
                {
                    state.BuyedSpinnings[i] = ScrollLayoutElementSpinningForStore.StateType.Disable;
                    sp.State_Type = ScrollLayoutElementSpinningForStore.StateType.Disable;
                }
                else
                {
                    state.BuyedSpinnings[i] = sp.State_Type;
                }                  
            }

          
        }

        public void Load(Unitity.Storage.SaveData state)
        {
            for (int i = 0; i < totalPriceList.Count; i++)
            {
                ScrollLayoutElementSpinningForStore sp = totalPriceList[i];
                if (i < state.BuyedSpinnings.Count)
                    sp.State_Type = state.BuyedSpinnings[i];
            }
        }
    }
}
